
CMAKE_MINIMUM_REQUIRED( VERSION 3.0 FATAL_ERROR )
if(COMMAND cmake_policy)
	cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

if(COMMAND cmake_policy)
	cmake_policy(SET CMP0011 NEW)
endif(COMMAND cmake_policy)

INCLUDE(${CMAKE_CURRENT_LIST_DIR}/arch.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/directory.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/utils.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/ops.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/files.cmake)

SET(CMAKE_C_STANDARD 99)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CCOMMON_OPT} ${ARCH_COMPLE_FLAG} -fpermissive -fstack-protector")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CCOMMON_OPT} ${ARCH_COMPLE_FLAG} -fstack-protector")
SET(ASM_OPTIONS "-x assembler-with-cpp")
SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS}" )

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb3 -O0")
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -ggdb3 -O0")
else()
  SET(CMAKE_BUILD_TYPE "Release")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CCOMMON_OPT}  -fpermissive -fstack-protector ")
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CCOMMON_OPT} -fstack-protector ")
  if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -strip-all ")
  elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")  
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ")
  endif()
endif()

if(THINKER_USE_OPENMP)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
endif(THINKER_USE_OPENMP)

SET(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${CCOMMON_LINKER_OPT}")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CCOMMON_LINKER_OPT}")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CCOMMON_LINKER_OPT}")

INCLUDE_DIRECTORIES(
  ${ROOT_SRC_DIR}/include/
)

MESSAGE(STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}") 
MESSAGE(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}") 
MESSAGE(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") 
MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") 
